<?php
	require_once 'LoginHandler.php';
	require_once 'LoginView.php';
	
    class LoginController{
    	
		public function DoControll(){
			// Creates a view
			$login = new LoginView();
			
			// Runs LoginHandler and tests if user is logged in or not
			$LH = new LoginHandler();
			if ($LH -> isLoggedIn()) {
				$body =$login->displayMessage(LoginView::RIGHT). $login->DoLogoutBox();		
			}
			else{
					
				// Pass username and password as argument
				$body = $login->displayMessage(LoginView::NOT). $login->DoLoginBox('','');
				
			}
			
			if ($login ->TriedToLogin()) {
				if ($LH ->DoLogin($login->GetUserName(), $login->GetPassword())) {
					if ($login ->rememberMe()) {
						$login ->setCookies();
					}
					header("Location:index.php");
				}
				else {
					$body .= $login->displayMessage(LoginView::WRONG);
				}
							
			}
			
			if ($login ->TriedToLogOut()) {
				$LH ->DoLogOut();
				header("Location:index.php");			
			}
			
			return $body;
		}
				
	}
?>